Addison Wesley : Patterns of Enterprise Application Architecture by By Martin Fowler David Rice Matthew Foemmel Edward Hieatt Robert Mee Randy Stafford
Author:By Martin Fowler, David Rice, Matthew Foemmel, Edward Hieatt, Robert Mee, Randy Stafford [By Martin Fowler, David Rice, Matthew Foemmel, Edward Hieatt, Robert Mee, Randy Stafford]
Language: eng
Format: epub
ISBN: 0321127420
Publisher: Addison Wesley
Published: 0101-01-01T00:00:00+00:00
Updates and Deletes
After all of that, updates and deletes are mostly harmless. Again we have an abstract method for the assumed usual case and an override for the special cases.
Updates work like this:
class AbstractMapper... public void update(DomainObjectWithKey subject) { PreparedStatement stmt = null; try { stmt = DB.prepare(updateStatementString()); loadUpdateStatement(subject, stmt); stmt.execute(); } catch (SQLException e) { throw new ApplicationException(e); } finally { DB.cleanUp(stmt); } } abstract protected String updateStatementString(); abstract protected void loadUpdateStatement(DomainObjectWithKey subject, PreparedStatement stmt) throws SQLException; class OrderMapper... protected void loadUpdateStatement(DomainObjectWithKey subject, PreparedStatement stmt) throws SQLException { Order order = (Order) subject; stmt.setString(1, order.getCustomer()); stmt.setLong(2, order.getKey().longValue()); } protected String updateStatementString() { return "UPDATE orders SET customer = ? WHERE id = ?"; } class LineItemMapper... protected String updateStatementString() { return "UPDATE line_items " + " SET amount = ?, product = ? " + " WHERE orderId = ? AND seq = ?"; } protected void loadUpdateStatement(DomainObjectWithKey subject, PreparedStatement stmt) throws SQLException { stmt.setLong(3, orderID(subject.getKey())); stmt.setLong(4, sequenceNumber(subject.getKey())); LineItem li = (LineItem) subject; stmt.setInt(1, li.getAmount()); stmt.setString(2, li.getProduct()); }
Deletes work like this:
class AbstractMapper... public void delete(DomainObjectWithKey subject) { PreparedStatement stmt = null; try { stmt = DB.prepare(deleteStatementString()); loadDeleteStatement(subject, stmt); stmt.execute(); } catch (SQLException e) { throw new ApplicationException(e); } finally { DB.cleanUp(stmt); } } abstract protected String deleteStatementString(); protected void loadDeleteStatement(DomainObjectWithKey subject, PreparedStatement stmt) throws SQLException { stmt.setLong(1, subject.getKey().longValue()); } class OrderMapper... protected String deleteStatementString() { return "DELETE FROM orders WHERE id = ?"; } class LineItemMapper... protected String deleteStatementString() { return "DELETE FROM line_items WHERE orderid = ? AND seq = ?"; } protected void loadDeleteStatement(DomainObjectWithKey subject, PreparedStatement stmt) throws SQLException { stmt.setLong(1, orderID(subject.getKey())); stmt.setLong(2, sequenceNumber(subject.getKey())); }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Brazilian Economy since the Great Financial Crisis of 20072008 by Philip Arestis Carolina Troncoso Baltar & Daniela Magalhães Prates(131117)
International Integration of the Brazilian Economy by Elias C. Grivoyannis(103444)
The Art of Coaching by Elena Aguilar(53099)
Flexible Working by Dale Gemma;(23279)
How to Stop Living Paycheck to Paycheck by Avery Breyer(19672)
The Acquirer's Multiple: How the Billionaire Contrarians of Deep Value Beat the Market by Tobias Carlisle(12294)
Thinking, Fast and Slow by Kahneman Daniel(12183)
The Radium Girls by Kate Moore(11990)
The Art of Thinking Clearly by Rolf Dobelli(10358)
Hit Refresh by Satya Nadella(9096)
The Compound Effect by Darren Hardy(8894)
Tools of Titans by Timothy Ferriss(8331)
Atomic Habits: Tiny Changes, Remarkable Results by James Clear(8279)
Turbulence by E. J. Noyes(7994)
A Court of Wings and Ruin by Sarah J. Maas(7762)
Change Your Questions, Change Your Life by Marilee Adams(7704)
Nudge - Improving Decisions about Health, Wealth, and Happiness by Thaler Sunstein(7671)
How to Be a Bawse: A Guide to Conquering Life by Lilly Singh(7447)
Win Bigly by Scott Adams(7155)